package com.example.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.dao.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * 功能描述
 *  用户角色mapper
 * @author: jimmy
 * @date: 2024年01月01日 17:05
 */
@Repository
public interface UserRoleMapper extends BaseMapper<UserRole> {
    /**
     * 根据用户id和角色id删除用户角色
     * @param userRole
     * @return
     */
    @Delete("<script>"+
            "delete " +
            " from " +
            "sys_users_roles " +
            "where user_id=#{userId} and " +
            "role_id=#{roleId} " +
            "</script>")
    int deleteUserRoleByBothId(UserRole userRole);

    /**
     * 根据角色id查询总数，检查该角色是否分配给用户
     * @param roleId
     * @return
     */
    @Select("<script>"+
            "select count(1) total " +
            " from " +
            "sys_users_roles " +
            "where  " +
            "role_id=#{roleId} " +
            "</script>")
    int findUserCountByRoleId(Long roleId);
}
